package com.zsc.koail.camerarecorder.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.widget.VideoView;

/**
 * @author zsc
 * @create 2018/8/6 0006
 * @Describe
 */
public class DisplayVideoView extends VideoView {
    private int mode = 1;

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        if (mode == 0) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        } else {
            setMeasuredDimension(widthMeasureSpec,heightMeasureSpec);
        }
    }

    public DisplayVideoView(Context context) {
        super(context);
    }

    public DisplayVideoView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DisplayVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    /**
     * 设备屏幕的宽度，以像素为单位
     *
     * @return
     */
    public static int getDVW(Context context) {
        DisplayMetrics dm = context.getResources().getDisplayMetrics();
        return dm.widthPixels;
    }

    /**
     * 设备屏幕的高度，以像素为单位
     *
     * @return
     */
    public static int getDVH(Context context) {
        DisplayMetrics dm = context.getResources().getDisplayMetrics();
        return dm.heightPixels;
    }
}
